import {RequestParam,HttpRequest} from '@/utils/http'

/**
 * 产品类目服务
 */
export const CategoryService={
	getCategories:function(){
		const request = new RequestParam();
		request.url = "/api/category/all.do";
		return HttpRequest(request);
	}
}

/**
 * 运费服务
 */
export const FreightService={
	getFreightTitle:function(productId,latitude,longitude,province,city){
		const request = new RequestParam();
		request.url = "/api/freight/title.do";
		request.param={productId:productId,latitude:latitude,longitude:longitude,province:province,city:city}
		return HttpRequest(request);
	}
}

/**
 * 产品服务
 */
export const ProductService = {
	// 热卖产品
	listHots: function(type) {
		const request = new RequestParam();
		request.url = "/api/product/list.do";
		request.param={tag:1,pageNo:1,pageSize:10}
		return HttpRequest(request);
	},
	// 产品列表
	list: function(param){
		const request = new RequestParam();
		request.url = "/api/product/list.do";
		request.param=param;
		return HttpRequest(request);
	},
	// 产品详情
	detail: function(productId){
		const request = new RequestParam();
		request.url = "/api/product/detail.do";
		request.param={productId:productId}
		return HttpRequest(request);
	},
	// 收藏的产品
	listFavorite(){
		const request = new RequestParam();
		request.url = "/api/product/list/favorite.do";
		return HttpRequest(request);
	},
	// 首页秒杀产品
	listRecommendSeckill(){
		return this.listSeckill({pageNo:1,pageSize:5})
	},
	// 秒杀产品列表
	listSeckill(param){
		const request = new RequestParam();
		request.url = "/api/product/seckill/list.do";
		request.param=param;
		return HttpRequest(request);
	},
	// 秒杀产品详情
	detailSeckill(secKillId){
		const request = new RequestParam();
		request.url = "/api/product/seckill/detail.do";
		request.param={secKillId:secKillId}
		return HttpRequest(request);
	}
}

/**
 * 产品收藏服务
 */
export const FavoriteService = {
	// 检查是否收藏过某个产品
	checkFavorite: function(productId) {
		const request = new RequestParam();
		request.url = "/api/product//check/favorite.do";
		request.param={productId:productId}
		return HttpRequest(request);
	},
	// 收藏产品
	favorite: function(productId){
		const request = new RequestParam();
		request.url = "/api/product/favorite.do";
		request.param={productId:productId};
		return HttpRequest(request);
	},
	// 取消收藏产品
	unFavorite: function(productId){
		const request = new RequestParam();
		request.url = "/api/product/unfavorite.do";
		request.param={productId:productId}
		return HttpRequest(request);
	}
}